/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package b_and_b_properties.data;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
/*
 *
 * @author Omea
 */

@Entity
@Table(name = "UNIT", catalog = "", schema = "SAPCAPSTONE")
@NamedQueries({
    @NamedQuery(name = "Unit.findAll", query = "SELECT u FROM Unit u"),
    @NamedQuery(name = "Unit.findByIdunit", query = "SELECT u FROM Unit u WHERE u.idunit = :idunit"),
    @NamedQuery(name = "Unit.findByPropertyIdproperty", query = "SELECT u FROM Unit u WHERE u.propertyIdproperty = :propertyIdproperty"),
    @NamedQuery(name = "Unit.findByUnitid", query = "SELECT u FROM Unit u WHERE u.unitid = :unitid"),
    @NamedQuery(name = "Unit.findByApartmentlevel", query = "SELECT u FROM Unit u WHERE u.apartmentlevel = :apartmentlevel"),
    @NamedQuery(name = "Unit.findBySecuritydeposit", query = "SELECT u FROM Unit u WHERE u.securitydeposit = :securitydeposit"),
    @NamedQuery(name = "Unit.findBySecurityamount", query = "SELECT u FROM Unit u WHERE u.securityamount = :securityamount"),
    @NamedQuery(name = "Unit.findByListdate", query = "SELECT u FROM Unit u WHERE u.listdate = :listdate"),
    @NamedQuery(name = "Unit.findByParkingoffstreet", query = "SELECT u FROM Unit u WHERE u.parkingoffstreet = :parkingoffstreet"),
    @NamedQuery(name = "Unit.findByParkingassigned", query = "SELECT u FROM Unit u WHERE u.parkingassigned = :parkingassigned"),
    @NamedQuery(name = "Unit.findByGaragespaces", query = "SELECT u FROM Unit u WHERE u.garagespaces = :garagespaces"),
    @NamedQuery(name = "Unit.findByHeatincluded", query = "SELECT u FROM Unit u WHERE u.heatincluded = :heatincluded"),
    @NamedQuery(name = "Unit.findByWaterincluded", query = "SELECT u FROM Unit u WHERE u.waterincluded = :waterincluded"),
    @NamedQuery(name = "Unit.findBySeparategaselectric", query = "SELECT u FROM Unit u WHERE u.separategaselectric = :separategaselectric"),
    @NamedQuery(name = "Unit.findBySeparateac", query = "SELECT u FROM Unit u WHERE u.separateac = :separateac"),
    @NamedQuery(name = "Unit.findBySeparatefurnace", query = "SELECT u FROM Unit u WHERE u.separatefurnace = :separatefurnace"),
    @NamedQuery(name = "Unit.findByDisabilityaccess", query = "SELECT u FROM Unit u WHERE u.disabilityaccess = :disabilityaccess"),
    @NamedQuery(name = "Unit.findByUlevel", query = "SELECT u FROM Unit u WHERE u.ulevel = :ulevel"),
    @NamedQuery(name = "Unit.findByBasement", query = "SELECT u FROM Unit u WHERE u.basement = :basement"),
    @NamedQuery(name = "Unit.findByNumberofrooms", query = "SELECT u FROM Unit u WHERE u.numberofrooms = :numberofrooms"),
    @NamedQuery(name = "Unit.findByNumberoffireplaces", query = "SELECT u FROM Unit u WHERE u.numberoffireplaces = :numberoffireplaces"),
    @NamedQuery(name = "Unit.findByDiningroom", query = "SELECT u FROM Unit u WHERE u.diningroom = :diningroom"),
    @NamedQuery(name = "Unit.findByFamilyroom", query = "SELECT u FROM Unit u WHERE u.familyroom = :familyroom"),
    @NamedQuery(name = "Unit.findByFirstfloorbath", query = "SELECT u FROM Unit u WHERE u.firstfloorbath = :firstfloorbath"),
    @NamedQuery(name = "Unit.findByFirstfloorbdrm", query = "SELECT u FROM Unit u WHERE u.firstfloorbdrm = :firstfloorbdrm"),
    @NamedQuery(name = "Unit.findByLeaseamount", query = "SELECT u FROM Unit u WHERE u.leaseamount = :leaseamount"),
    @NamedQuery(name = "Unit.findByLeasedate", query = "SELECT u FROM Unit u WHERE u.leasedate = :leasedate")})
public class Unit implements Serializable {

    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "IDUNIT")
    private Integer idunit;
    @Column(name = "UNITID")
    private Integer unitid;
    @Column(name = "APARTMENTLEVEL")
    private Integer apartmentlevel;
    @Column(name = "NUMBEROFBEDROOMS")
    private int numberOfBedrooms;
    @Column(name = "SECURITYDEPOSIT")
    private Character securitydeposit;
    @Column(name = "SECURITYAMOUNT")
    private Double securityamount;
    @Column(name = "LISTDATE")
    @Temporal(TemporalType.DATE)
    private Date listdate;
    @Column(name = "PARKINGOFFSTREET")
    private Integer parkingoffstreet;
    @Column(name = "PARKINGASSIGNED")
    private Integer parkingassigned;
    @Column(name = "GARAGESPACES")
    private Integer garagespaces;
    @Column(name = "HEATINCLUDED")
    private Integer heatincluded;
    @Column(name = "WATERINCLUDED")
    private Integer waterincluded;
    @Column(name = "SEPARATEGASELECTRIC")
    private Integer separategaselectric;
    @Column(name = "SEPARATEAC")
    private Integer separateac;
    @Column(name = "SEPARATEFURNACE")
    private Integer separatefurnace;
    @Column(name = "DISABILITYACCESS")
    private Integer disabilityaccess;
    @Column(name = "ULEVEL")
    private Integer ulevel;
    @Column(name = "BASEMENT")
    private String basement;
    @Column(name = "NUMBEROFROOMS")
    private Integer numberofrooms;
    @Column(name = "NUMBEROFFIREPLACES")
    private Integer numberoffireplaces;
    @Column(name = "NUMBEROFBATHROOMS")
    private Integer numberofbathrooms;
    @Column(name = "DININGROOM")
    private Integer diningroom;
    @Column(name = "FAMILYROOM")
    private Integer familyroom;
    @Column(name = "FIRSTFLOORBATH")
    private Integer firstfloorbath;
    @Column(name = "FIRSTFLOORBDRM")
    private Integer firstfloorbdrm;
    @Column(name = "LEASEAMOUNT")
    private Double leaseamount;
    @Column(name = "LEASEDATE")
    @Temporal(TemporalType.DATE)
    private Date leasedate;
    @Column(name = "TENANTNAME")
    private String tenantName;
    @JoinColumn(name = "PROPERTY_IDPROPERTY", referencedColumnName = "IDPROPERTY")
    @ManyToOne(optional = false)
    private Property propertyIdproperty;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "unitIdunit")
    private List<Room> roomList = new ArrayList<Room>();

    public Unit() {
    }

    public Unit(Integer idunit) {
        this.idunit = idunit;
    }

//    public Unit(Integer idunit, int propertyIdproperty) {
//        this.idunit = idunit;
//        this.propertyIdproperty = propertyIdproperty;
//    }
//
//    public Unit(Property parent) {
//        this.idunit = idunit;
//        this.propertyIdproperty = propertyIdproperty;
//    }
    public Integer getIdunit() {
        return idunit;
    }

    public void setIdunit(Integer idunit) {
        Integer oldIdunit = this.idunit;
        this.idunit = idunit;
        changeSupport.firePropertyChange("idunit", oldIdunit, idunit);
    }

    public Integer getNumberOfBedrooms() {
        return numberOfBedrooms;
    }

    public void setNumberOfBedrooms(Integer numberOfBedrooms) {
        Integer oldNumberOfBedrooms = this.numberOfBedrooms;
        this.numberOfBedrooms = numberOfBedrooms;
        changeSupport.firePropertyChange("numberofbathrooms", oldNumberOfBedrooms, numberOfBedrooms);
    }

    public Integer getNumberOfBathrooms() {
        return numberofbathrooms;
    }

    public void setNumberOfBathrooms(Integer numberofbathrooms) {
        Integer oldnumberofbathrooms = this.numberofbathrooms;
        this.numberofbathrooms = numberOfBedrooms;
        changeSupport.firePropertyChange("numberofbedrooms", oldnumberofbathrooms, numberofbathrooms);
    }
//    public Property getPropertyIdproperty() {
//        return propertyIdproperty;
//    }
//
//    public void setPropertyIdproperty(Property propertyIdproperty) {
//        Property oldPropertyIdproperty = this.propertyIdproperty;
//        this.propertyIdproperty = propertyIdproperty;
//        //changeSupport.firePropertyChange("propertyIdproperty", oldPropertyIdproperty, propertyIdproperty);
//    }

    public Integer getUnitid() {
        return unitid;
    }

    public void setUnitid(Integer unitid) {
        Integer oldUnitid = this.unitid;
        this.unitid = unitid;
        changeSupport.firePropertyChange("unitid", oldUnitid, unitid);
    }

    public Integer getApartmentlevel() {
        return apartmentlevel;
    }

    public void setApartmentlevel(Integer apartmentlevel) {
        Integer oldApartmentlevel = this.apartmentlevel;
        this.apartmentlevel = apartmentlevel;
        changeSupport.firePropertyChange("apartmentlevel", oldApartmentlevel, apartmentlevel);
    }

    public Character getSecuritydeposit() {
        return securitydeposit;
    }

    public void setSecuritydeposit(Character securitydeposit) {
        Character oldSecuritydeposit = this.securitydeposit;
        this.securitydeposit = securitydeposit;
        changeSupport.firePropertyChange("securitydeposit", oldSecuritydeposit, securitydeposit);
    }

    public Double getSecurityamount() {
        return securityamount;
    }

//    @Constraint(Constraint.Type.NUMERIC)
//    @MinInclusive(0)
//    @MaxInclusive(5000.00)
    public void setSecurityamount(Double securityamount) {
        Double oldSecurityamount = this.securityamount;
        this.securityamount = securityamount;
        changeSupport.firePropertyChange("securityamount", oldSecurityamount, securityamount);
    }

    public Date getListdate() {
        return listdate;
    }

    public void setListdate(Date listdate) {
        Date oldListdate = this.listdate;
        this.listdate = listdate;
        changeSupport.firePropertyChange("listdate", oldListdate, listdate);
    }

    public Integer getParkingoffstreet() {
        return parkingoffstreet;
    }

    public void setParkingoffstreet(Integer parkingoffstreet) {
        Integer oldParkingoffstreet = this.parkingoffstreet;
        this.parkingoffstreet = parkingoffstreet;
        changeSupport.firePropertyChange("parkingoffstreet", oldParkingoffstreet, parkingoffstreet);
    }

    public Integer getParkingassigned() {
        return parkingassigned;
    }

    public void setParkingassigned(Integer parkingassigned) {
        Integer oldParkingassigned = this.parkingassigned;
        this.parkingassigned = parkingassigned;
        changeSupport.firePropertyChange("parkingassigned", oldParkingassigned, parkingassigned);
    }

    public Integer getGaragespaces() {
        return garagespaces;
    }

    public void setGaragespaces(Integer garagespaces) {
        Integer oldGaragespaces = this.garagespaces;
        this.garagespaces = garagespaces;
        changeSupport.firePropertyChange("garagespaces", oldGaragespaces, garagespaces);
    }

    public Integer getHeatincluded() {
        return heatincluded;
    }

    public void setHeatincluded(Integer heatincluded) {
        Integer oldHeatincluded = this.heatincluded;
        this.heatincluded = heatincluded;
        changeSupport.firePropertyChange("heatincluded", oldHeatincluded, heatincluded);
    }

    public Integer getWaterincluded() {
        return waterincluded;
    }

    public void setWaterincluded(Integer waterincluded) {
        Integer oldWaterincluded = this.waterincluded;
        this.waterincluded = waterincluded;
        changeSupport.firePropertyChange("waterincluded", oldWaterincluded, waterincluded);
    }

    public Integer getSeparategaselectric() {
        return separategaselectric;
    }

    public void setSeparategaselectric(Integer separategaselectric) {
        Integer oldSeparategaselectric = this.separategaselectric;
        this.separategaselectric = separategaselectric;
        changeSupport.firePropertyChange("separategaselectric", oldSeparategaselectric, separategaselectric);
    }

    public Integer getSeparateac() {
        return separateac;
    }

    public void setSeparateac(Integer separateac) {
        Integer oldSeparateac = this.separateac;
        this.separateac = separateac;
        changeSupport.firePropertyChange("separateac", oldSeparateac, separateac);
    }

    public Integer getSeparatefurnace() {
        return separatefurnace;
    }

    public void setSeparatefurnace(Integer separatefurnace) {
        Integer oldSeparatefurnace = this.separatefurnace;
        this.separatefurnace = separatefurnace;
        changeSupport.firePropertyChange("separatefurnace", oldSeparatefurnace, separatefurnace);
    }

    public Integer getDisabilityaccess() {
        return disabilityaccess;
    }

    public void setDisabilityaccess(Integer disabilityaccess) {
        Integer oldDisabilityaccess = this.disabilityaccess;
        this.disabilityaccess = disabilityaccess;
        changeSupport.firePropertyChange("disabilityaccess", oldDisabilityaccess, disabilityaccess);
    }

    public Integer getUlevel() {
        return ulevel;
    }

    public void setUlevel(Integer ulevel) {
        Integer oldUlevel = this.ulevel;
        this.ulevel = ulevel;
        changeSupport.firePropertyChange("ulevel", oldUlevel, ulevel);
    }

    public String getBasement() {
        return basement;
    }

    public void setBasement(String basement) {
        String oldBasement = this.basement;
        this.basement = basement;
        changeSupport.firePropertyChange("basement", oldBasement, basement);
    }

    public Integer getNumberofrooms() {
        return numberofrooms;
    }

    public void setNumberofrooms(Integer numberofrooms) {
        Integer oldNumberofrooms = this.numberofrooms;
        this.numberofrooms = numberofrooms;
        changeSupport.firePropertyChange("numberofrooms", oldNumberofrooms, numberofrooms);
    }

    public Integer getNumberoffireplaces() {
        return numberoffireplaces;
    }

    public void setNumberoffireplaces(Integer numberoffireplaces) {
        Integer oldNumberoffireplaces = this.numberoffireplaces;
        this.numberoffireplaces = numberoffireplaces;
        changeSupport.firePropertyChange("numberoffireplaces", oldNumberoffireplaces, numberoffireplaces);
    }

    public Integer getDiningroom() {
        return diningroom;
    }

    public void setDiningroom(Integer diningroom) {
        Integer oldDiningroom = this.diningroom;
        this.diningroom = diningroom;
        changeSupport.firePropertyChange("diningroom", oldDiningroom, diningroom);
    }

    public Integer getFamilyroom() {
        return familyroom;
    }

    public void setFamilyroom(Integer familyroom) {
        Integer oldFamilyroom = this.familyroom;
        this.familyroom = familyroom;
        changeSupport.firePropertyChange("familyroom", oldFamilyroom, familyroom);
    }

    public Integer getFirstfloorbath() {
        return firstfloorbath;
    }

    public void setFirstfloorbath(Integer firstfloorbath) {
        Integer oldFirstfloorbath = this.firstfloorbath;
        this.firstfloorbath = firstfloorbath;
        changeSupport.firePropertyChange("firstfloorbath", oldFirstfloorbath, firstfloorbath);
    }

    public Integer getFirstfloorbdrm() {
        return firstfloorbdrm;
    }

    public void setFirstfloorbdrm(Integer firstfloorbdrm) {
        Integer oldFirstfloorbdrm = this.firstfloorbdrm;
        this.firstfloorbdrm = firstfloorbdrm;
        changeSupport.firePropertyChange("firstfloorbdrm", oldFirstfloorbdrm, firstfloorbdrm);
    }

    public Double getLeaseamount() {
        return leaseamount;
    }

    public void setLeaseamount(Double leaseamount) {
        Double oldLeaseamount = this.leaseamount;
        this.leaseamount = leaseamount;
        changeSupport.firePropertyChange("leaseamount", oldLeaseamount, leaseamount);
    }

    public Date getLeasedate() {
        return leasedate;
    }

    public void setLeasedate(Date leasedate) {
        Date oldLeasedate = this.leasedate;
        this.leasedate = leasedate;
        changeSupport.firePropertyChange("leasedate", oldLeasedate, leasedate);
    }

    public Property getPropertyIdproperty() {
        return propertyIdproperty;
    }

    public void setPropertyIdproperty(Property propertyIdproperty) {
        Property oldPropertyIdproperty = this.propertyIdproperty;
        this.propertyIdproperty = propertyIdproperty;
        changeSupport.firePropertyChange("propertyIdproperty", oldPropertyIdproperty, propertyIdproperty);
    }
       

    public String getTenantName() {
        return tenantName;
    }

    public void setTenantName(String tenantName) {
        String oldtenantName = this.tenantName;
        this.tenantName = tenantName;
        changeSupport.firePropertyChange("TENANTNAME", tenantName, tenantName);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idunit != null ? idunit.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Unit)) {
            return false;
        }
        Unit other = (Unit) object;
        if ((this.idunit == null && other.idunit != null) || (this.idunit != null && !this.idunit.equals(other.idunit))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "b_and_b_properties.data.Unit[ idunit=" + idunit + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

    public List<Room> getRoomListAsList() {
        return this.roomList;
//        return roomList;
    }

    public Room[] getRoomListAsArray() {
        return (Room[]) this.roomList.toArray();
//        return roomList;
    }

    public void setRoomList(Room[] roomList) {
        newRoomArray();
        for (Room u : roomList) {
            this.roomList.add(u);
        }
//        this.roomList = roomList;
    }

    public void newRoomArray() {
        this.roomList = new ArrayList<Room>();
    }

    public void newRoomArray(int size) {
        this.roomList = new ArrayList<Room>(size);
    }

    public Room getRoom(int roomNum) {
        return roomList.get(roomNum);
//        return roomList[roomNum];
    }

    public void setRoom(int index, Room room) {
        roomList.set(index, room);
//        roomList[index] = room;
    }

    public int getRoomArrayLength() {
        return roomList.size();
    }

    public void addRoom(Room room) {
        roomList.add(room);
    }
}
